﻿using System;
using System.Text;
using System.Data;
using VIT.Library.Web;
using VIT.Web.UI;

namespace VIT.Web.Modules.Survey
{
    public partial class SurveyView : VITComponent
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            DataSet ds = new DataSet();
            StringBuilder xml = new StringBuilder();
            xml.Append(this.URLBaseDir);
            xml.Append(this.URLCurrentPath);
            xml.Append("\\Survey.xml");
            ds.ReadXml(xml.ToString());

            if (!IsPostBack)
            {
                if (Request.Params.Get("vote") != null)
                {
                    string v = Request.Params.Get("vote").ToString();
                    ds.Tables[0].Rows[int.Parse(v)]["vote"] = int.Parse(ds.Tables[0].Rows[int.Parse(v)]["vote"].ToString()) + 1;
                    ds.WriteXml(xml.ToString());
                }
            }

            Bieuquyet(ds);

            rpt.DataSource = ds.Tables[0];
            rpt.DataBind();
        }
        private void Bieuquyet(DataSet ds)
        {
            double total = 0;
            foreach (DataRow dr in ds.Tables[0].Rows) total += double.Parse(dr["vote"].ToString());
            foreach (DataRow row in ds.Tables[0].Rows)
            {
                row["per"] = (double.Parse(row["vote"].ToString()) * 100 / total).ToString("#,##.00");
            }
        }
    }
}